net/tftp: Fix stack buffer overflow in tftp_open()
authorB Horn <b@horn.uk>
Thu, 18 Apr 2024 16:32:34 +0000 (17:32 +0100)
committerFelix Zielcke <fzielcke@z-51.de>
Wed, 11 Jun 2025 15:42:34 +0000 (17:42 +0200)
commit22c4e3fb0b70095cde1227feb8ae7fda571b5a81
tree630b172fdde57fc1da2de71560ef740dd3d7b9eb
parent206992e2d9d33dc5b820a0d41a88dcd3f659b441
net/tftp: Fix stack buffer overflow in tftp_open()

An overly long filename can be passed to tftp_open() which would cause
grub_normalize_filename() to write out of bounds.

Fixed by adding an extra argument to grub_normalize_filename() for the
space available, making it act closer to a strlcpy(). As several fixed
strings are strcpy()'d after into the same buffer, their total length is
checked to see if they exceed the remaining space in the buffer. If so,
return an error.

On the occasion simplify code a bit by removing unneeded rrqlen zeroing.

Reported-by: B Horn <b@horn.uk>
Signed-off-by: B Horn <b@horn.uk>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Gbp-Pq: Topic cve-2025-jan
Gbp-Pq: Name net-tftp-Fix-stack-buffer-overflow-in-tftp_open.patch
grub-core/net/tftp.c